<template>
    <div class="article-edit">
        <el-card class="!border-none" shadow="never">
            <el-page-header :content="$route.meta.title" @back="$router.back()" />
        </el-card>
        <el-card class="mt-4 !border-none" shadow="never">
            <el-form ref="formRef" class="ls-form" :model="formData" label-width="85px" :rules="rules">
                <div class="xl:flex">
                    <div>
                        <el-form-item label="温馨提示" prop="name_m">
                            <div class="ww">
                                <!-- <el-input v-model="formData.value" placeholder="请输入温馨提示" /> -->
								 <el-input
								    v-model="formData.value"
								    autosize
								    type="textarea"
								    placeholder="Please input"
								  />
                            </div>
                        </el-form-item>


                    </div>

                </div>
            </el-form>
        </el-card>
        <footer-btns>
            <el-button type="primary" @click="handleSave">保存</el-button>
        </footer-btns>
    </div>
</template>

<script lang="ts" setup name="articleListsEdit">
import type { FormInstance } from 'element-plus'
import { useDictOptions } from '@/hooks/useDictOptions'
import { articleDetail, articleEdit, articleAdd, articleCateAll,getAll,getxiu,getwenxinAdd } from '@/api/article'
import useMultipleTabs from '@/hooks/useMultipleTabs'

const route = useRoute()
const router = useRouter()
const formData = reactive({
    id: '',
    value: ''
})

const { removeTab } = useMultipleTabs()
const formRef = shallowRef<FormInstance>()
// const rules = reactive({
//     title: [{ required: true, message: '请输入文章标题', trigger: 'blur' }],
//     cid: [{ required: true, message: '请选择文章栏目', trigger: 'blur' }]
// })

const getDetails = async () => {
    const data = await getAll({
        id: route.query.id
    })
	let data1=data.shuju
    Object.keys(formData).forEach((key) => {
        //@ts-ignore
        formData[key] = data1[key]
    })
}

const { optionsData } = useDictOptions<{
    article_cate: any[]
}>({
    article_cate: {
        api: articleCateAll
    }
})

const handleSave = async () => {
    await formRef.value?.validate()
	console.log(formData.value,'formData.value');
	
    if (route.query.id) {
        await getxiu(formData)
    } else {
		let value1={
			value:formData.value
		}
        await getwenxinAdd(value1)
    }
    removeTab()
    router.back()
}

route.query.id && getDetails()
</script>
<style>
	.ww{
		width:500px
	}
</style>
